<template>
  <div>
    <template v-for="item in this.menuList">
      <!-- 如果有子菜单，渲染 el-submenu -->
      <el-submenu
        v-if="item.children && item.children.length > 0"
        :index="item.menuId"
        :popper-append-to-body="false"
        :popper-class="item.isExpand === 1 ? 'expanded' : 'collapsed'"
      >
        <template #title>
          <i :class="item.icon"></i>
          <span>{{ item.menuName }}</span>
        </template>
        <!-- 递归渲染子菜单 -->
        <MenuTree :menuList="item.children" />
      </el-submenu>

      <!-- 如果没有子菜单，渲染 el-menu-item -->
      <el-menu-item
        v-else
        :index="item.url"
        @click="savePath(item.url)"
      >
        <i :class="item.icon"></i>
        <span>{{ item.menuName }}</span>
      </el-menu-item>
    </template>
  </div>

</template>

<script>
export default {
  name: 'MenuTree',
  //menuList  这是home传过来的菜单集合【属于父传子组件】
  props: ["menuList","tagList"],
  methods:{
    //保存激活路径
    savePath(path) {
      window.sessionStorage.setItem("activePath", path);
      this.activePath = path;
    },
  },
};
</script>

<style scoped>
.el-menu-item.is-active {
  background-color: #E2E9F9 !important;
  color: #fff !important;
}

.expanded {
  display: block;
}

.collapsed {
  display: none;
}
</style>
